package cn.tedu.objectx;

public class Demo {
    public static void main(String[] args) throws CloneNotSupportedException {
       //创建Object的对象--无参构造
//        Object obj = new Object();
//        System.out.println(obj);//java.lang.Object@28d93b30
        //向上造型
//        Object obj = new Person();
//        Object obj1 = new Student();
        //数组对象也可以赋值给Object引用
//        Object obj2 = new int[3];

        //clone
        Person p = new Person();
        p.name = "张三";
        p.age = 18;
        System.out.println(p.name+","+p.age);

        //Person对象 需要和p对象的属性值一模一样
//        Person p1 = new Person();
//        p1.name = p.name;
//        p1.age = p.age;
//        System.out.println(p1.name+","+p1.age);
//        p.clone();//编译会报错 protected 权限修饰符的问题
//        Object obj = p.method();
//        Person p1 = (Person) obj;
//        System.out.println(p1.name+p1.age);
//        System.out.println(p);
//        System.out.println(p1);

        Person p1 = p.clone();

    }
    //Object类型作为方法的参数
//    public static void method(Object obj){
//
//    }
}
class Person implements Cloneable{
    String name;
    int age;
    //重写Object中的clone 为了放大权限修饰符
    @Override
    public Person clone() throws CloneNotSupportedException {
        return (Person)super.clone();
    }
    //自定义方法来完成克隆
//    public Object method() throws CloneNotSupportedException {
//        Object obj = this.clone();//运行抛出异常
//        return obj;
//    }
}
//class Student extends Person{}